<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" trimDirectiveWhitespaces="true"%>
<%@ page import="java.util.Date"%>
<%@ include file="../security/include.inc.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title>加盟商信息</title>
</head>
<body>
    <div class="mini-fit">
    	<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
            <table style="width:100%;">
                <tr>
                    <td style="width:100%;">
                        <a class="mini-button" iconCls="icon-add" onclick="addRow()" plain="true">增加</a>
                        <span class="separator"></span>
                        <a class="mini-button" iconCls="icon-remove" onclick="removeRow()" plain="true">删除</a>
                        <span class="separator"></span>
                        <a class="mini-button" iconCls="icon-save" onclick="saveData()" plain="true">保存</a> 
                    </td>
                </tr>
            </table>           
        </div>
	    <div id="datagrid1" class="mini-datagrid" style="width:100%;height:90%;" allowCellEdit="true" allowCellSelect="true" multiSelect="true" editNextOnEnterKey="true" fitColumns="false" showPager="false" 
		url="<%=basePath%>/channelInfo/list">
			<div property="columns">
				<div type="indexcolumn"></div>
				<div field="channel_id" width="100" headerAlign="center" vtype="required">加盟商编号
					<input property="editor" class="mini-textbox" style="width: 100%;" />
				</div>
				<div field="channel_name" width="100" headerAlign="center">加盟商名称
					<input property="editor" class="mini-textbox" style="width: 100%;" />
				</div>
				<div field="intro_staff" width="100" headerAlign="center">推荐人
					<input property="editor" class="mini-combobox" url="<%=basePath%>/user/list"  textField="realname" valueField="username" style="width: 100%;" />
				</div>
				<div field="create_date" width="100" headerAlign="center" dateFormat="yyyy-MM-dd">创建时间
					<input property="editor" class="mini-datepicker" style="width: 100%;" />
				</div>
				<div field="channel_url" width="100" headerAlign="center">加盟商网站链接
					<input property="editor" class="mini-textbox" style="width: 100%;" />
				</div>
			</div>
			
		</div>
    </div>
	
	<script type="text/javascript">
	 	mini.parse();
		var grid = mini.get("datagrid1");
	    grid.load();
	    
		//////////////////////////////////////////////////////
		
		
		function search() {       
            var obj = {};
            if("" != mini.get("cbl1").getValue()){
            	obj.yearSection = mini.get("cbl1").getValue();
            }
            var locationSection = mini.get("cbl2").getValue();
            if("" != locationSection && locationSection.indexOf("100000") < 0){
            	obj.locationSection = mini.get("cbl2").getValue();
            }
            var json = mini.encode(obj);
            grid.load({ key: json });
        }
        
        function reset(){
        	mini.get("cbl1").setValue();
        	mini.get("cbl2").setValue();
        }
        
        function addRow() {          
            var newRow = { name: "New Row"};
            grid.addRow(newRow, 0);
        }
        function removeRow() {
            var rows = grid.getSelecteds();
            if (rows.length > 0) {
                grid.removeRows(rows, true);
            }
        }
        function saveData() {
            var data = grid.getChanges();
            
            if(data.length == 0) return;
            
            
            var json = mini.encode(data);
            
            console.log(data);
            
             grid.loading("保存中，请稍后......");
             $.ajax({
                url: "<%=basePath%>/channelInfo/save",
                 data: { data: json },
                 type: "post",
                 success: function (text) {
                	 alert(text);
                     grid.reload();
                 },
                 error: function (jqXHR, textStatus, errorThrown) {
                     alert(jqXHR.responseText);
                 }
             });
        }
        function toggleFieldSet(ck, id) {
            var dom = document.getElementById(id);
            dom.className = !ck.checked ? "hideFieldset" : "";
        }
        
	</script>
</body>
</html>